package com.xhwl.centiotdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhwl.centiotdata.dao.IOrgInfoDao;
import com.xhwl.centiotdata.service.IOrgInfoService;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.iot.OrgInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author pengjunming
 * @description
 * @date 2022/7/4 17:30
 */
@Service
public class OrgInfoServiceImpl extends ServiceImpl<IOrgInfoDao, OrgInfo> implements IOrgInfoService {
    @Resource
    private IOrgInfoDao orgInfoDao;

    @Override
    public ResultJson<OrgInfo> getOrgInfoById(Integer id, Integer productId) {
        return ResultJson.successWithResult(getOrgInfo(id, productId));
    }

    @Override
    public void deleteOrgInfo(Integer id, Integer productId) {
        remove(new LambdaQueryWrapper<OrgInfo>().eq(OrgInfo::getId, id).eq(OrgInfo::getProductId, productId));
    }

    @Override
    public OrgInfo getOrgInfo(Integer id, Integer productId) {
        return getOne(new LambdaQueryWrapper<OrgInfo>().eq(OrgInfo::getId, id).eq(OrgInfo::getProductId, productId));
    }

    @Override
    public void updateOrgInfo(OrgInfo orgInfo) {
        update(orgInfo, new LambdaQueryWrapper<OrgInfo>().eq(OrgInfo::getId, orgInfo.getId()).eq(OrgInfo::getProductId, orgInfo.getProductId()));
    }

    @Override
    public List<OrgInfo> getList(Integer productId, List<Integer> ids) {
        LambdaQueryWrapper<OrgInfo> queryWrapper = new LambdaQueryWrapper<OrgInfo>().eq(OrgInfo::getProductId, productId);
        if (ids != null && !ids.isEmpty()) {
            queryWrapper.in(OrgInfo::getId, ids);
        }
        return orgInfoDao.selectList(queryWrapper);
    }
}
